package com.lyy.utils;


import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * jdbc工具类,获取druid数据库连接池对象
 */
public class JdbcUtils {
    private static DataSource dataSource;

    static {
        try {
            // 1.加载配置文件
            Properties pro=new Properties();
            pro.load(JdbcUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
            // 2.获取dataSource
            dataSource= DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("数据库连接池创建失败,e:"+e.toString());
        }
    }

    public static DataSource getDataSource(){
        return dataSource;
    }

}
